package com.newworld.dmsapp2.activity.designtask;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.newworld.dmsapp2.BaseActivity;
import com.newworld.dmsapp2.R;
import com.newworld.dmsapp2.activity.designtask.adapter.ServerAdapter;
import com.newworld.dmsapp2.bean.InitOperation;
import com.newworld.dmsapp2.bean.Server;
import com.newworld.dmsapp2.bean.Task;
import com.newworld.dmsapp2.util.Config;

/**
 * 
 * @author long 显示服务人员列表的activity
 */
public class SelectServerActivity extends BaseActivity implements
		OnClickListener {

	private Intent intent;
	private Bundle bundle;
	private ExpandableListView serverEpdLv;
	private ServerAdapter adapter;
	private List<Server> serverList = new ArrayList<Server>();
	private Server server;
	private TextView titleCenterTv;
	private LinearLayout leftLinLayout;
	private String functionCode;
	private String repairId;
	private String houseId;
	private String peopleType;
	private String taskstate;
	private InitOperation initOP;
	private Task task;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_select_server);
		initData();
		initViews();
		initEvents();
	}

	@SuppressWarnings("unchecked")
	private void initData(){
		intent = getIntent();
		bundle = intent.getExtras();
		if (bundle != null) {
			task = (Task) bundle.getSerializable(Config.TASK);
			server = (Server) bundle.getSerializable(Config.SERVERAFTER);
			functionCode=bundle.getString(Config.FUNCTIONCODE);
			repairId=bundle.getString(Config.REPAIRID);
			houseId = bundle.getString(Config.HOUSEID);
			peopleType = bundle.getString(Config.PEOPLETYPE);
			initOP = (InitOperation) bundle.getSerializable(Config.INITOPERATION);
			taskstate = bundle.getString(Config.TASKSTATE);
			serverList = (List<Server>) bundle.getSerializable(Config.SERVERLIST);
		}
		
		for (Server s : serverList) {
			if (s.isSelected()) {
				server = s;
			}
		}
	}
	@Override
	protected void initViews() {
		// TODO Auto-generated method stub
		titleCenterTv = (TextView) findViewById(R.id.titlebar_left_center_title);
		serverEpdLv = (ExpandableListView) findViewById(R.id.epdLt_server);
		leftLinLayout = (LinearLayout) findViewById(R.id.titlebar_left_left_layout);

		titleCenterTv.setText("人员分配");
		

		adapter = new ServerAdapter(SelectServerActivity.this, serverList, server,initOP,task);
		serverEpdLv.setAdapter(adapter);

		for (int i = 0; i < adapter.getGroupCount(); i++) {

			serverEpdLv.expandGroup(i);

		}
		adapter.notifyDataSetChanged();

	}

	@Override
	protected void initEvents() {
		// TODO Auto-generated method stub
		leftLinLayout.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.titlebar_left_left_layout:
			finish();
			
			
		}
	}

}
